// pages/index/taskdetail.js
var api = require('../../api.js'), Api = require("../../utils/util.js"),
  app = getApp();
var WxParse = require('../../wxParse/html2json.js');
Page({
  data: {
    show: true,
    shows: false,
    assignmentid:0,
    feedbackShow:!0,
    feedbackdetail:"",
  },
  onLoad: function(options) {
    var _that = this
    var user = wx.getStorageSync("user")
    this.onpageRefresh(options)
    options.shows == 'true' && _that.setData({
      shows: options.shows
    })
    _that.setData({
      assignmentid: options.assignmentid
    })
    // 任务动态
    app.request({
      url: api.taskAssigned.comments,
      method: 'POST',
      data: {
        uid: options.uid,
        isadministrator: user.isadministrator,
        assignmentId: options.assignmentid
      },
      success: function(res) {
        var List = res.data.data.comments
        // List.map(function (index, item) {
        //   index.ctime = Api.toDate(index.ctime)
        // })
        List.map(function (inex, item) {
          inex["ctime"] = WxParse.html2json(inex["ctime"], 'returnData');
          // newinfo.push(inex.content)
        })
        _that.setData({
          Lists: List
        })
         
        console.log("任务动态========>", res)
      }
    })
  },

  //任务详情页面
  onpageRefresh: function(options) {
    var _that = this
    _that.setData({
      uid: options.uid,
      assignmentId: options.assignmentid
    })
    app.request({
      url: api.taskAssigned.taskdetail,
      method: 'POST',
      data: {
        uid: options.uid,
        assignmentId: options.assignmentid
      },
      success: function(res) {
        _that.setData({
          List: res

        })
        console.log("已任务详细页面========>", res)
      }
    })
  },
  // 编辑
  btnEditor: function() {
    var _that =  this
    wx.navigateTo({
      url: '/pages/index/newCreate?indexss=' + 0 + '&description=' + _that.data.List.data.assignment.description + '&msid=' + _that.data.assignmentid,
    })
  },
  // 反馈信息
  feedback(e){
    console.log(e)
    let _this = this
    _this.setData({
      feedbackShow: !_this.data.feedbackShow
    })
  },
  // 实时获取反馈信息
  changefeedback(res){
    console.log(res)
    let that = this
    that.setData({
      feedbackdetail:res.detail.value
    })
  },
  // 防止这遮罩层穿透
  stop(){
    return false
  },
  // 已完成
  btnEnd: function(t) {
    var _that = this
    var uid = _that.data.uid
    var assignmentId = _that.data.assignmentId    
    var feedbackdetail = _that.data.feedbackdetail;

   
    if (feedbackdetail == undefined || feedbackdetail == ''){
      wx.showModal({
        title: '提示',
        content: '请填写信息',
      })
      return false;
    }

    app.request({
      url: api.taskAssigned.taskend,
      method: "POST",
      data: {
        uid: uid,
        assignmentId: assignmentId,
        feedbackdetail: feedbackdetail
      },
      success: function(res) {
        setTimeout(function() {
          _that.setData({
            show: false
          })
        }, 3000)
        wx.navigateTo({
          url: '/pages/index/index'
        })
        console.log("已完成=====>", res)
      }
    })
  },
  onReady: function() {

  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  }
})